package com.schooldate.model.entity;

import com.schooldate.annotation.JsonIncludeField;
import com.schooldate.base.BaseVo;
import org.hibernate.search.annotations.*;
import org.hibernate.search.annotations.Index;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


/**
 *
 * Created by etund on 2015/4/25 0025.
 */
@Indexed
@Entity
public class ExamSource extends BaseVo {

    @Id
    @Column(name = "id",length = 10)
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column
    @Field(index= Index.YES, analyze=Analyze.YES, store=Store.NO)
    private String name;

    @Transient
    private List<String> sourcePathes = new ArrayList<String>();



    @Field(index= Index.YES, analyze=Analyze.YES, store=Store.NO)
    private String title;

    @Transient
    @Field(index= Index.YES, analyze=Analyze.YES, store=Store.NO)
    private String content;

    @Column
    private Long examSourceId;

    @Column(length = 1000)
    private String sourcePath;

    @ManyToOne(targetEntity = UserInfo.class,cascade = CascadeType.MERGE)
    @JoinColumn(name = "userInfoId")
    private UserInfo userInfo;

    @ManyToOne(targetEntity = School.class,cascade = CascadeType.MERGE)
    @JoinColumn(name = "schoolInfoId")
    private School school;

    @ManyToOne(targetEntity = Department.class,cascade = CascadeType.MERGE)
    @JoinColumn(name = "departmentId")
    private Department department;

    @JsonIncludeField(namespace = {"searchSource.do"})
    public String getSourcePath() {
        return sourcePath;
    }

    public void setSourcePath(String sourcePath) {
        this.sourcePath = sourcePath;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @JsonIncludeField(namespace = {"searchSource.do"})
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @JsonIncludeField(namespace = {"searchSource.do"})
    public Long getExamSourceId() {
        return examSourceId;
    }

    public void setExamSourceId(Long examSourceId) {
        this.examSourceId = examSourceId;
    }

    public List<String> getSourcePathes() {
        String[] str = this.getSourcePath().split(",");
        for (int i = 0;i<str.length;i++){
            sourcePathes.add(str[i]);
        }
        return sourcePathes;
    }

    public UserInfo getUserInfo() {
        return userInfo;
    }

    public void setUserInfo(UserInfo userInfo) {
        this.userInfo = userInfo;
    }

    public School getSchool() {
        return school;
    }

    public void setSchool(School school) {
        this.school = school;
    }

    public Department getDepartment() {
        return department;
    }

    public void setDepartment(Department department) {
        this.department = department;
    }
}
